#include "AdjacencyListGraph.h"

using namespace CloudZ;

AdjacencyListGraph::AdjacencyListGraph()
{
}

AdjacencyListGraph::~AdjacencyListGraph()
{
}

void AdjacencyListGraph::addEdge(int v, int u)
{
	if (v >= _adjacencyLists.size()) _adjacencyLists.resize(v + 1);
	if (u >= _adjacencyLists.size()) _adjacencyLists.resize(u + 1);
	_adjacencyLists[v].push_back(u);
	_adjacencyLists[u].push_back(v);
}

std::list<int> & AdjacencyListGraph::getEdges(int v)
{
	return _adjacencyLists[v];
}
void AdjacencyListGraph::print(std::ostream &out)
{
	/*
	for (std::vector<std::list<int>>::const_iterator it = this->_adjacencyLists.begin();
		it != this->_adjacencyLists.end();
		++it)
	{
		
	}*/
	for (int i = 0; i < this->_adjacencyLists.size(); i++)
	{
		out << i << ": ";

		if (this->_adjacencyLists[i].size() > 0)
		{
			std::list<int>::iterator it = this->_adjacencyLists[i].begin();
			out << *(it++);

			for (;
				it != (this->_adjacencyLists[i].end());
				++it)
			{
				out  << ", " << *it;
			}
			
		}
		
		out << std::endl;
	}
}
